﻿//--------------------------------------------------------------------------------------------------------------
// <copyright file="CSPStreetMap.cs" company="Microsoft Corporation" author="David Martos" date="01/02/2008">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//--------------------------------------------------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
using System.Web.UI.WebControls.WebParts;
using System.ComponentModel;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;

using CSP.LoggingEngine;
using System.Xml;
using Microsoft.SharePoint.Utilities;



namespace CSP.WebParts
{
    /// <summary>
    /// This webpart gets the key attractions
    /// </summary>
    [Guid("2850C485-364B-47d2-AFA4-E8BBAF00C520")]
    public class CSPKeyAttractions : BaseWebPart
    {

        #region WebPart Members

        /// <summary>
        /// Web user control which defines the output of the webpart
        /// </summary>
        protected UserControls.CSPKeyAttractionsWUC control;
        #endregion

        #region WebPart Properties

        private string listSite;
        private string listName;
        private string iconsLibraryUrl;
        private const string ListSiteDefault = "visitors";
        private const string ListNameDefault = "KeyAttractions";

        /// <summary>
        /// URL of the library which stores POI icons
        /// </summary>
        [WebBrowsable(true), Personalizable(true)]
        [ResourcesAttribute("MapParamIconsLibraryUrl", "CSPWebPartParameterCategory", "MapParamIconsLibraryUrlDescription")]        
        public string IconsLibraryUrl
        {
            get { return iconsLibraryUrl; }
            set { iconsLibraryUrl = value; }
        }

        /// <summary>
        /// Sharepoint site where the Key Attractions list is stored
        /// </summary>
        [WebBrowsable(true), Personalizable(true)]
        [ResourcesAttribute("MapParamKeyAttractionsSite", "CSPWebPartParameterCategory", "MapParamKeyAttractionsSiteDescription")]
        [DefaultValue(ListSiteDefault)]
        public string ListSite
        {
            get { return listSite; }
            set { listSite = value; }
        }

        /// <summary>
        /// Name of the Key Attractions list
        /// </summary>
        [WebBrowsable(true), Personalizable(true)]
        [ResourcesAttribute("MapParamKeyAttractionsList", "CSPWebPartParameterCategory", "MapParamKeyAttractionsListDescription")]
        [DefaultValue(ListNameDefault)]
        public string ListName
        {
            get { return listName; }
            set { listName = value; }
        }

        #endregion

        public CSPKeyAttractions()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        /// <summary>
        /// When created, this webpart loads its web user control and sets its public variables
        /// </summary>
        protected override void CreateChildControls()
        {

            base.CreateChildControls();
            try
            {
                if (listSite.Equals(string.Empty) || listName.Equals(string.Empty))
                {
                    this.LogMessage(this.LoadResource(WebPartConstants.CSPKeyAttractionsProperyListErrorMessage), this.GetType().Name);
                }
                else
                {
                    control = (UserControls.CSPKeyAttractionsWUC)this.Page.LoadControl(WebPartConstants.CSPKeyAttractionsWUCLocation);
                    control.WrapperWebPart = this;
                    control.IconsLibraryUrl = this.iconsLibraryUrl;
                    control.ListSite = this.listSite;
                    control.ListName = this.listName;
                    this.Controls.Add(control);
                }
            } 
            catch (CSP.Core.CSPException cspex)
            {
                errors.Add(this.LoadResource(WebPartConstants.CSPGenericErrorMessage));
            }
            catch (Exception ex)
            {
                this.LogMessage(this.LoadResource(WebPartConstants.CSPGenericErrorMessage), this.GetType().Name, ex);
                errors.Add(this.LoadResource(WebPartConstants.CSPGenericErrorMessage));
            }
        }


    }
}
